package com.flower.service.impl;

import com.flower.mapper.ProductsMapper;
import com.flower.model.entity.PageQuery;
import com.flower.model.entity.Product;
import com.flower.result.PageResult;
import com.flower.service.ProductsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName ProductsServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/10 14:58
 *@Version 1.0
 */
@Service
public class ProductsServiceImpl implements ProductsService {
    @Autowired
    private ProductsMapper productsMapper;

    @Override
    public List<Product> getProducts() {
        List<Product> products = productsMapper.getAllProducts();
        return products;
    }

    @Override
    public Product getProduct(Integer id) {
        Product product = productsMapper.getProduct(id);
        return product;
    }

    @Override
    public PageResult pageQuery(PageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPageNum(), pageQuery.getPageSize());
        Page<Product> page = productsMapper.pageQuery(pageQuery);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public List<Product> list() {
        return productsMapper.list();
    }

    @Override
    public void saveBatch(List<Product> products) {
        products.forEach(product -> productsMapper.add(product));
    }
}
